-
-
Notifications
You must be signed in to change notification settings - Fork 529
CEF performance improvements #4634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
Good job! |
|
Would it be possible to add the codecs to this CEF version? I’m thinking of the fact that, for example, YouTube live streams currently don’t work for this reason. These codec packs are not included in minimal CEF build. (H.264 & AAC) |
This is unlikely due to licensing, we can't distribute those codecs. |
|
Good job, I can't wait for this to be implemented in new versions. |
Dirty rect 'optimizations' were actually lowering performance, and causing edge case issues with device restoration and partial updates - removed this functionality. Also improved device reset/restore handling (force repaint)
Summary
This update significantly improves the performance and memory efficiency of MTA's CEF browser implementation.
Non-blocking render thread synchronization
The most impactful change is replacing the old blocking synchronization model, where CEF's render thread would wait up to 250ms for the main thread, with External Begin Frame scheduling that allows MTA to request frames on-demand in sync with the game loop.
Memory optimizations
Memory consumption is reduced by switching browser textures from D3DPOOL_MANAGED to D3DPOOL_DEFAULT with D3DUSAGE_DYNAMIC, eliminating the duplicate system RAM copy that managed textures require.
Resource allocation improvements
Lazy browser creation defers CEF subprocess spawning until the first URL is actually loaded, avoiding resource allocation for unused browser instances.
Enable GPU compositing
GPU compositing and hardware video decoding are now properly enabled when the GPU setting is on, which drastically improves YouTube and video playback performance.
This also adds a new setting "Enable video acceleration" to the web browser settings menu.
!! IMPORTANT NOTE !!
Previously GPU compositing was unconditionally disabled due to previous stability concerns in release builds - this must be thoroughly tested in both nightly and official release streams
Mouse input/polling throttle
Additionally, mouse input throttling limits move events from being completely unbounded, to around 60 per second, reducing unnecessary CEF repaints while maintaining smooth cursor tracking.
Together, these changes reduce CPU overhead, lower memory footprint, improve video playback, and provide more stable frame rates.
Additionally, I've provided a more detailed summary of each change below.
The "changes made" sections provide a detailed/technical overview of the notable changes.
The "benefits" sections provide a higher level summary of what has changed, and why.
External Begin Frame Scheduling
Changes made:
CWebView.h:
CWebView.cpp:
CWebCore.cpp:
Benefits:
Use D3DPOOL_DEFAULT with D3DUSAGE_DYNAMIC
Changes made to CRenderItem.WebBrowser.cpp:
CreateUnderlyingData():
OnLostDevice():
OnResetDevice():
Changes made to CWebView.cpp:
Benefits:
Lazy Browser Creation
Changes made:
CWebView.h:
CWebView.cpp:
Benefits:
Video Decode Acceleration & GPU Compositing
Changes made:
CClientVariables.cpp:
CSettings.h:
CSettings.cpp:
CWebApp.cpp:
Benefits:
Mouse Input Throttling
Changes made:
CWebView.h:
CWebView.cpp:
Benefits:
Motivation
After some recent discussions surrounding main menu revamp / GUI changes in the development discord (see #main-menu-revamp), and testing CEF myself, I noticed the performance in certain areas was quite poor (e.g YouTube videos choppy, inconsistent framerates, etc).
Many servers already rely on CEF for the majority of their UI, so we must ensure it runs as smooth as possible, especially if we're even going to consider using CEF ourselves for main menu UI (which some users do seem interested in).
Test plan
Here's a small CEF test resource which implements a tiny CEGUI-based browser window, with the ability to go back/forward, refresh & enter URLs directly into the 'address bar': cef.zip
Just load the resource, and you'll see instructions in chat. This also tests the lazy loading functionality.
Compared to builds without these improvements, I'm seeing a 10-20% FPS improvement in some cases, frame times are more consistent, and video playback is much smoother.
There are some really good tests on this site which actually cover some specific test cases based on the changes made above: https://frameratetest.com/
For example https://frameratetest.com/mouse-polling-rate-test/ can be used to ensure the mouse polling changes are properly enforcing the 60hz limit.
There's various sites like this out there anyway - just have a browse around and compare to builds without these changes and you're sure to see improvements.
Well, if you're still not convinced, check out the video examples below. The first is from MTA's official release (latest) - and the second is from my custom build with these changes (both fps_limit 999 on server + client). Even after multiple compressions of the video files you can still clearly see the difference - it's even easier to notice when you test the changes yourself!
MTA official release
https://www.youtube.com/watch?v=mGIOUSHIFGQ
Custom build
https://www.youtube.com/watch?v=hZljFFxa2H0
Checklist